﻿Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes

Partial Public Class PlayerSelection 
	Inherits UserControl

	Public Sub New()
		' Required to initialize variables
    InitializeComponent()

    PlayerType = Players.None

    RadioButtonComputer.Content = My.Resources.Texts.PlayerTypeComputer
    RadioButtonHuman.Content = My.Resources.Texts.PlayerTypePlayer
    RadioButtonNone.Content = My.Resources.Texts.PlayerTypeNone

    TextBlockGood.Text = My.Resources.Texts.ComputerLevelGood
    TextBlockBad.Text = My.Resources.Texts.ComputerLevelBad
	End Sub

  Public Enum Players
    Player
    Computer
    None
  End Enum

  ''' <summary>
  ''' type of player: computer, player or none.
  ''' </summary>
  Public Property PlayerType() As Players
    Get
      Select Case True
        Case RadioButtonHuman.IsChecked
          Return Players.Player
        Case RadioButtonComputer.IsChecked
          Return Players.Computer
        Case RadioButtonNone.IsChecked
          Return Players.None
        Case Else
          RadioButtonNone.IsChecked = True
          Return Players.None
      End Select
    End Get
    Set(ByVal value As Players)
      Select Case value
        Case Players.Computer
          RadioButtonComputer.IsChecked = True
        Case Players.Player
          RadioButtonHuman.IsChecked = True
        Case Else
          RadioButtonNone.IsChecked = True
      End Select
    End Set
  End Property

  ''' <summary>
  ''' name of the (human) player
  ''' </summary>
  ''' <value></value>
  Public Property PlayerName() As String
    Get
      Return TextBoxPlayerName.Text
    End Get
    Set(ByVal value As String)
      TextBoxPlayerName.Text = value
    End Set
  End Property

  ''' <summary>
  ''' level of play when player is a computer
  ''' </summary>
  Public Property ComputerPlayLevel() As Integer
    Get
      Return CInt(SliderLevel.Value)
    End Get
    Set(ByVal value As Integer)
      SliderLevel.Value = value
    End Set
  End Property


#Region "RadioButton workaround"
  'group property can't be used, because it is active outside
  'the context of this usercontrol, ie the radio buttons on 2
  'different instances of this control react on each other

  Private Sub RadioButtonHuman_Checked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    RadioButtonComputer.IsChecked = False
    RadioButtonNone.IsChecked = False
    BorderPlayer.Visibility = Windows.Visibility.Visible
    BorderComputer.Visibility = Windows.Visibility.Collapsed
  End Sub

  Private Sub RadioButtonComputer_Checked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    RadioButtonHuman.IsChecked = False
    RadioButtonNone.IsChecked = False
    BorderPlayer.Visibility = Windows.Visibility.Collapsed
    BorderComputer.Visibility = Windows.Visibility.Visible
  End Sub

  Private Sub RadioButtonNone_Checked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    RadioButtonHuman.IsChecked = False
    RadioButtonComputer.IsChecked = False
    BorderPlayer.Visibility = Windows.Visibility.Collapsed
    BorderComputer.Visibility = Windows.Visibility.Collapsed
  End Sub
#End Region
End Class
